/**
 * Created by Administrator on 2017/4/1 0001.
 */
var PageTouch0={
    create:function () {
        var page={};
        var time;

        page.ui=new PIXI.DisplayObjectContainer();

        var sp_bg=new PIXI.Sprite(resource['assets/images/pt0_bg.png'].texture);
        sp_bg.anchor.set(0.0);
        sp_bg.x = 0;
        sp_bg.y = 0;
        // page.ui.addChild(sp_bg);

        var arr_piece=[];
        for(var i=0;i<20;i++)
        {
            // var texture=resource["assets/images/pt0_bg.png"].texture.clone();
            // var square=new PIXI.Rectangle(0,1136/300*i,740,1136/300);
            // texture.frame=square;
            // var piece=new PIXI.Sprite(texture);
            // piece.x=0;
            // piece.y=1136/300*i;
            // arr_piece.push(piece);
            // page.ui.addChild(piece);
            var texture=resource["assets/images/pt0_bg.png"].texture.clone();
            var square=new PIXI.Rectangle(740/20*i,0,740/20,1136);
            texture.frame=square;
            var piece=new PIXI.Sprite(texture);
            piece.x=740/20*i;
            piece.y=0;
            arr_piece.push(piece);
            page.ui.addChild(piece);

        }

        //sp_bg.interactive=true;
        //sp_bg.on('pointerdown',downHandler);

        var con_text=new PIXI.DisplayObjectContainer();
        page.ui.addChild(con_text);

        var gp_alpha=new PIXI.Graphics();
        gp_alpha.beginFill(0,0.0);
        gp_alpha.drawRect(0,0,740,1136);
        gp_alpha.endFill();
        con_text.addChild(gp_alpha);

        var t0=new PIXI.Sprite(resource['assets/images/pt0_t0.png'].texture);
        t0.anchor.set(0.5);
        con_text.addChild(t0);
        t0.x=109;
        t0.y=545;
        var mask_0=new PIXI.Graphics();
        mask_0.beginFill(0,1);
        mask_0.drawCircle(0,0,182);
        mask_0.endFill();
        mask_0.x=t0.x;
        mask_0.y=t0.y;
        mask_0.scale.x=mask_0.scale.y=0;
        con_text.addChild(mask_0);
        t0.mask=mask_0;

        var t1=new PIXI.Sprite(resource['assets/images/pt0_t1.png'].texture);
        t1.anchor.set(0.5);
        con_text.addChild(t1);
        t1.x=219;
        t1.y=545;
        var mask_1=new PIXI.Graphics();
        mask_1.beginFill(0,1);
        mask_1.drawCircle(0,0,182);
        mask_1.endFill();
        mask_1.x=t1.x;
        mask_1.y=t1.y;
        mask_1.scale.x=mask_1.scale.y=0;
        con_text.addChild(mask_1);
        t1.mask=mask_1;

        var t2=new PIXI.Sprite(resource['assets/images/pt0_t2.png'].texture);
        t2.anchor.set(0.5);
        con_text.addChild(t2);
        t2.x=354;
        t2.y=545;
        var mask_2=new PIXI.Graphics();
        mask_2.beginFill(0,1);
        mask_2.drawCircle(0,0,182);
        mask_2.endFill();
        mask_2.x=t2.x;
        mask_2.y=t2.y;
        mask_2.scale.x=mask_2.scale.y=0;
        con_text.addChild(mask_2);
        t2.mask=mask_2;

        var t3=new PIXI.Sprite(resource['assets/images/pt0_t3.png'].texture);
        t3.anchor.set(0.5);
        con_text.addChild(t3);
        t3.x=483;
        t3.y=545;
        var mask_3=new PIXI.Graphics();
        mask_3.beginFill(0,1);
        mask_3.drawCircle(0,0,182);
        mask_3.endFill();
        mask_3.x=t3.x;
        mask_3.y=t3.y;
        mask_3.scale.x=mask_3.scale.y=0;
        con_text.addChild(mask_3);
        t3.mask=mask_3;

        var t4=new PIXI.Sprite(resource['assets/images/pt0_t4.png'].texture);
        t4.anchor.set(0.5);
        con_text.addChild(t4);
        t4.x=616;
        t4.y=545;
        var mask_4=new PIXI.Graphics();
        mask_4.beginFill(0,1);
        mask_4.drawCircle(0,0,182);
        mask_4.endFill();
        mask_4.x=t4.x;
        mask_4.y=t4.y;
        mask_4.scale.x=mask_4.scale.y=0;
        con_text.addChild(mask_4);
        t4.mask=mask_4;


        var pt0_info0=Easy.CreateSprite('assets/images/pt0_info0.png',370,990,0.5,0.5,1);

        var click=Easy.CreateSprite('assets/images/pt0_bt.png',370,547,0.5,0.5,0);
        click.on('pointerdown',downHandler);
        click.on('pointerup',upHandler);
        page.ui.addChild(click);


        var maskIdx=0;
        page.In2=function (idx) {
            maskIdx=idx;
            time=setInterval(function () {
                createCircle();
            },1000);

            // setTimeout(function () {
            //     clearInterval(time);
            // },6000)

            click.alpha=0;
            click.scale.x=click.scale.y=3;
            TweenMax.to(click.scale,1,{delay:2.5,x:1,y:1,ease:Back.easeOut});
            TweenMax.to(click,1,{delay:2.5,alpha:1,ease:Back.easeOut,onComplete:function()
            {
                console.log('true!!');
                click.interactive=true;
            }});

            // for(var i=arr_piece.length-1;i>-1;i--)
            // {
            //     arr_piece[i].x=-740+(i%2)*1480;
            //     arr_piece[i].alpha=1;
            //     TweenMax.to(arr_piece[i],0.5,{delay:i*0.005,alpha:1,x:0,ease:Cubic.easeInOut});
            // }
            for(var i=0;i<arr_piece.length;i++)
            {
                arr_piece[i].y=-1136+(i%2)*1136*2;
                arr_piece[i].alpha=1;
                TweenMax.to(arr_piece[i],0.5,{delay:i*0.05,alpha:1,y:0,ease:Cubic.easeInOut});
            }
        }

        page.In=function() {
            //t2.mask=
            t0.scale.x = t0.scale.y = 2.5;
            mask_0.scale.x = mask_0.scale.y = 0;
            TweenMax.to(t0.scale, 1, {delay: 1 + 0.2 * 0, x: 1, y: 1, ease: Cubic.easeOut});
            TweenMax.to(mask_0.scale, 1, {delay: 1 + 0.2 * 0, x: 1, y: 1, ease: Back.easeOut,onComplete:function () {
                t0.mask.alpha=0;
                t0.mask.parent.removeChild(t0.mask);
                t0.mask=null;
            }});

            t1.scale.x = t1.scale.y = 2.5;
            mask_1.scale.x = mask_1.scale.y = 0;
            TweenMax.to(t1.scale, 1, {delay: 1 + 0.2 * 1, x: 1, y: 1, ease: Cubic.easeOut});
            TweenMax.to(mask_1.scale, 1, {delay: 1 + 0.2 * 1, x: 1, y: 1, ease: Back.easeOut,onComplete:function () {
                t1.mask.alpha=0;
                t1.mask.parent.removeChild(t1.mask);
                t1.mask=null;
            }});

            t2.scale.x = t2.scale.y = 2.5;
            mask_2.scale.x = mask_2.scale.y = 0;
            TweenMax.to(t2.scale, 1, {delay: 1 + 0.2 * 2, x: 1, y: 1, ease: Cubic.easeOut});
            TweenMax.to(mask_2.scale, 1, {delay: 1 + 0.2 * 2, x: 1, y: 1, ease: Back.easeOut,onComplete:function () {
                t2.mask.alpha=0;
                t2.mask.parent.removeChild(t2.mask);
                t2.mask=null;
            }});

            t3.scale.x = t3.scale.y = 2.5;
            mask_3.scale.x = mask_3.scale.y = 0;
            TweenMax.to(t3.scale, 1, {delay: 1 + 0.2 * 3, x: 1, y: 1, ease: Cubic.easeOut});
            TweenMax.to(mask_3.scale, 1, {delay: 1 + 0.2 * 3, x: 1, y: 1, ease: Back.easeOut,onComplete:function () {
                t3.mask.alpha=0;
                t3.mask.parent.removeChild(t3.mask);
                t3.mask=null;
            }});

            t4.scale.x = t4.scale.y = 2.5;
            mask_4.scale.x = mask_4.scale.y = 0;
            TweenMax.to(t4.scale, 1, {delay: 1 + 0.2 * 4, x: 1, y: 1, ease: Cubic.easeOut});
            TweenMax.to(mask_4.scale, 1, {delay: 1 + 0.2 * 4, x: 1, y: 1, ease: Back.easeOut,onComplete:function () {
                t4.mask.alpha=0;
                t4.mask.parent.removeChild(t4.mask);
                t4.mask=null;
            }});

            time=setInterval(function () {
                createCircle();
            },1800);

            // setTimeout(function () {
            //     clearInterval(time)
            // },5000);
            setTimeout(function()
            {
                twistStart()
            },3000);


        }
        var fl;
        function twistStart()
        {
            fl= new PIXI.filters['TwistFilter']();
            fl.radius = 0;
            fl.angle = 0;
            fl.offset = new PIXI.Point(350*pixiStage.scale.x+pixiStage.x,510*pixiStage.scale.y+pixiStage.y);
            var arr=[];
            arr.push(fl)
           con_text.filters=[fl];


            twistOne();
        }
        function twistOne()
        {
            TweenMax.to(con_text,4,{alpha:0,ease:Cubic.easeOut,onComplete:function()
            {
                con_text.removeChild(t0);
                con_text.removeChild(mask_0);
                con_text.removeChild(t1);
                con_text.removeChild(mask_1);
                con_text.removeChild(t2);
                con_text.removeChild(mask_2);
                con_text.removeChild(t3);
                con_text.removeChild(mask_3);
                con_text.removeChild(t4);
                con_text.removeChild(mask_4);
                twistTwo();
            }});
            TweenMax.to(fl,4,{angle:20*pixiStage.scale.x,radius:650*pixiStage.scale.x,ease:Cubic.easeInOut});

            click.scale.x=click.scale.y=3;
            TweenMax.to(click.scale,1,{delay:3.7,x:1,y:1,ease:Back.easeOut});
            TweenMax.to(click,1,{delay:3.7,alpha:1,ease:Back.easeOut,onComplete:function()
            {
                console.log('true!!');
                click.interactive=true;
            }});
        }
        function twistTwo()
        {
            // con_text.alpha=0;
            // con_text.addChild(pt0_info0);
            // fl.angle=180;
            // fl.radius=100;
            // fl.offset.x=235;
            // fl.offset.y=510;
            // TweenMax.to(fl,2,{angle:0,radius:0,ease:Cubic.easeOut});
            // TweenMax.to(fl.offset,2,{x:220,y:600,ease:Cubic.easeOut});
            // TweenMax.to(con_text,2,{alpha:1,ease:Cubic.easeOut,onComplete:function()
            // {
            //
            // }});
            page.ui.addChild(pt0_info0);
            pt0_info0.alpha=0;
            pt0_info0.y=990+100
            TweenMax.to(pt0_info0,1,{alpha:1,y:990,ease:Back.easeOut});
        }
        function downHandler(e)
        {
            console.log('down')
            click.interactive=false;
            clearInterval(time);


            var detail='mask'+maskIdx.toString();
            document.dispatchEvent(new CustomEvent('Game_PageIn',{'detail':detail}));

            TweenMax.to(pt0_info0,1,{alpha:0});
        }
        function upHandler()
        {

        }

        function createCircle()
        {
            // for(var i=0;i<10;i++)
            // {
            //     var circle=Circle.create(0,0,0xcccccc);
            //     page.ui.addChild(circle.ui);
            //
            //     circle.ui.x=369;
            //     circle.ui.y=575;
            //
            //     circle.ui.scale.x=0;
            //     circle.ui.scale.y=0;
            //     TweenMax.to(circle.ui,1.1,{delay:0.1*i,alpha:0});
            //     TweenMax.to(circle.ui.scale,1.1,{delay:0.05*i,x:0.2-i*0.01,y:0.2-i*0.01,onCompleteParams:[circle],onComplete:function (c) {
            //         c.ui.parent.removeChild(c.ui);
            //         c=null;
            //     }});
            // }
            //
            // for(var i=0;i<10;i++)
            // {
            //     var circle=Circle.create(0,0,0xcccccc);
            //     page.ui.addChild(circle.ui);
            //
            //     circle.ui.x=369;
            //     circle.ui.y=575;
            //
            //     circle.ui.scale.x=0.15;
            //     circle.ui.scale.y=0.15;
            //     circle.alpha=0.8;
            //     TweenMax.to(circle.ui,1.1,{delay:0.1*i,alpha:0});
            //     TweenMax.to(circle.ui.scale,1.1,{delay:0.05*i,x:0.4-i*0.01,y:0.4-i*0.01,onCompleteParams:[circle],onComplete:function (c) {
            //         c.ui.parent.removeChild(c.ui);
            //         c=null;
            //     }});
            // }
            //
            // for(var i=0;i<10;i++)
            // {
            //     var circle=Circle.create(0,0,0xcccccc);
            //     page.ui.addChild(circle.ui);
            //
            //     circle.ui.x=369;
            //     circle.ui.y=575;
            //
            //     circle.ui.scale.x=0.35;
            //     circle.ui.scale.y=0.35;
            //     circle.alpha=0.7;
            //     TweenMax.to(circle.ui,1.1,{delay:0.1*i,alpha:0});
            //     TweenMax.to(circle.ui.scale,1.1,{delay:0.05*i,x:0.6-i*0.01,y:0.6-i*0.01,onCompleteParams:[circle],onComplete:function (c) {
            //         c.ui.parent.removeChild(c.ui);
            //         c=null;
            //     }});
            // }
            //
            // for(var i=0;i<10;i++)
            // {
            //     var circle=Circle.create(0,0,0xcccccc);
            //     page.ui.addChild(circle.ui);
            //
            //     circle.ui.x=369;
            //     circle.ui.y=575;
            //
            //     circle.ui.scale.x=0.55;
            //     circle.ui.scale.y=0.55;
            //     circle.alpha=0.6;
            //     TweenMax.to(circle.ui,1.1,{delay:0.1*i,alpha:0});
            //     TweenMax.to(circle.ui.scale,1.1,{delay:0.05*i,x:0.8-i*0.01,y:0.8-i*0.01,onCompleteParams:[circle],onComplete:function (c) {
            //         c.ui.parent.removeChild(c.ui);
            //         c=null;
            //     }});
            // }
            //
            // for(var i=0;i<10;i++)
            // {
            //     var circle=Circle.create(0,0,0xcccccc);
            //     page.ui.addChild(circle.ui);
            //
            //     circle.ui.x=369;
            //     circle.ui.y=575;
            //
            //     circle.ui.scale.x=0.75;
            //     circle.ui.scale.y=0.75;
            //     circle.alpha=0.5;
            //     TweenMax.to(circle.ui,1.1,{delay:0.1*i,alpha:0});
            //     TweenMax.to(circle.ui.scale,1.1,{delay:0.05*i,x:0.9-i*0.01,y:0.9-i*0.01,onCompleteParams:[circle],onComplete:function (c) {
            //         c.ui.parent.removeChild(c.ui);
            //         c=null;
            //     }});
            // }
            for(var i=0;i<15;i++)
            {
                var circle=Circle.create(0,0,0xcccccc);
                page.ui.addChild(circle.ui);

                circle.ui.x=369;
                circle.ui.y=550;

                circle.ui.scale.x=0.0;
                circle.ui.scale.y=0.0;
                circle.ui.alpha=0.0;
                TweenMax.to(circle.ui,0.25,{delay:0.1*i,alpha:1,ease:Linear.easeNone,onCompleteParams:[circle],onComplete:function (c) {
                    TweenMax.to(c.ui,0.25,{delay:0,alpha:0,ease:Linear.easeNone,onCompleteParams:[c],onComplete:function (c) {
                        TweenMax.to(c.ui,0.25,{delay:0,alpha:1,ease:Linear.easeNone,onCompleteParams:[c],onComplete:function (c) {
                            TweenMax.to(c.ui,0.25,{delay:0,alpha:0,ease:Linear.easeNone,onCompleteParams:[c],onComplete:function (c) {
                                TweenMax.to(c.ui,0.25,{delay:0,alpha:1,ease:Linear.easeNone,onCompleteParams:[c],onComplete:function (c) {
                                    TweenMax.to(c.ui,0.25,{delay:0,alpha:0,ease:Linear.easeNone,onCompleteParams:[c],onComplete:function (c) {
                                        TweenMax.to(c.ui,0.25,{delay:0,alpha:1,ease:Linear.easeNone,onCompleteParams:[c],onComplete:function (c) {
                                            TweenMax.to(c.ui,0.25,{delay:0,alpha:0,ease:Linear.easeNone,onCompleteParams:[c],onComplete:function (c) {

                                            }});
                                        }});
                                    }});
                                }});
                            }});
                        }});
                    }});
                }});
                // TweenMax.to(circle.ui,0.5,{alpha:1});
                // TweenMax.to(circle.ui,0.5,{delay:0.5,alpha:0});
                // TweenMax.to(circle.ui,0.5,{delay:1,alpha:1});
                // TweenMax.to(circle.ui,0.5,{delay:1.5,alpha:0});

                TweenMax.to(circle.ui.scale,3,{delay:0.1*i,x:0.5-i*0.0,y:0.5-i*0.0,onCompleteParams:[circle],onComplete:function (c) {

                    c.ui.parent.removeChild(c.ui);
                    c=null;
                }});
            }
        }

        return page;
    }
}